package com.youmu.shop.admin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.youmu.shop.admin.dao.AdminDao;
import com.youmu.shop.admin.service.AdminService;
import com.youmu.shop.role.dao.RoleDao;
import com.youmu.shop.system.bean.Admin;
import com.youmu.shop.system.bean.Role;

@Service
@Transactional
public class AdminServiceImpl implements AdminService{

	@Autowired
	private AdminDao adminDao;
	
	@Autowired
	private RoleDao roleDao;
	
	@Override
	public Integer insertSelective(Admin admin) {
		return adminDao.insertSelective(admin);
	}
	
	@Override
	public Admin selectAdminByUserNameForDispatching(String userName) {
		return adminDao.selectAdminByUserNameForDispatching(userName);
	}

	@Override
	public Admin checkAdminDispatchingType(Admin admin) {
		List<Role> list = roleDao.selectRolesByAdminId(admin.getId());
		for (Role role : list) {
			/**
			 * 自营
			 */
			if(role.getId() == 7L){
				admin.setDispatchingType(1);
			}
			/**
			 * 闪送
			 */
			if(role.getId() == 10){
				admin.setDispatchingType(2);
			}
			
			/**
			 * 第三方配送
			 */
			if(role.getId() == 11){
				admin.setDispatchingType(3);
			}
		}
		return admin;
	}
	
}
